package org.example.cli.command;

import cn.hutool.core.bean.BeanUtil;
import lombok.Data;
import org.example.generator.MainGenerator;
import org.example.model.MainTemplateConfig;
import picocli.CommandLine;

import java.util.concurrent.Callable;

/**
 * 生成代码命令
 * @author ricejson
 */
@Data
@CommandLine.Command(name = "generate", description = "生成代码", mixinStandardHelpOptions = true)
public class GeneratorCommand implements Callable<Integer> {

    /**
     * 是否循环
     */
    @CommandLine.Option(names = {"-l", "--loop"}, interactive = true, arity = "0..1", description = "是否循环", echo = true)
    private boolean loop;

    /**
     * 作者
     */
    @CommandLine.Option(names = {"-a", "--author"}, interactive = true, arity = "0..1", description = "作者", echo = true)
    private String author;

    /**
     * 输出文本
     */
    @CommandLine.Option(names = {"-o", "--outputText"}, interactive = true, arity = "0..1", description = "输出文本", echo = true)
    private String outputText;
    @Override
    public Integer call() throws Exception {
        MainTemplateConfig config = new MainTemplateConfig();
        BeanUtil.copyProperties(this, config);
        // 进行代码生成
        MainGenerator.doGenerate(config);
        return 0;
    }
}
